<template>
  <a-modal :maskClosable="false" :visible="visible" @ok="confirmSubmit" @cancel="close" width="500px">
    <a-card :bordered="false">
      <div>
        <span>请输入想要查询相似度</span>
        <a-input-number
          style="width:80px; margin:0 10px"
          :min="0"
          :max="100"
          :precision="2"
          v-model = "num"
        ></a-input-number>
        <span>%以上的组合</span>
      </div>
    </a-card>
  </a-modal>
</template>

<script>
import {STable} from '@/components'
import {doRecommendedProduction} from '@/api/modular/main/emsorder/emsOrderManage'

export default {
  components: {
    STable,
  },
  props: {
    onRowSelected: {}
  },
  data() {
    return {
      num:0,   //输入框数值
      visible: false,
      advanced: false, // 高级搜索 展开/关闭
      queryParam: {},  // 查询参数
      columns: [       // 表头
        // {
        //   title: '序号', width:'80px',
        //   dataIndex: 'index',
        //   key: 'index',
        //   align: 'center',
        //   customRender: (text, record, index) => `${index + 1}`,
        // },
        {
          title: 'BOM编码',
          dataIndex: 'bomCode'
        },
        {
          title: 'BOM名称',
          dataIndex: 'bomName'
        },
        {
          title: '优先级',
          dataIndex: 'bomClassSort'
        },
        {
          title: '数量',
          dataIndex: 'number'
        },
        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   width: '80px',
        //   scopedSlots: {customRender: 'action'}
        // }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        return doRecommendedProduction(Object.assign(parameter, this.record)).then((res) => {
          let rows = res.data
          return {
            pageNo: 1,
            totalRows: 99999,
            rows: rows
          }
        })
      },
      selectedRowKeys: [],
      selectedRows: [],
      defaultExpandedKeys: [],
      replaceFields: {
        key: 'id',
      },
      previewVisible: false,
      previewImage: '',
      record: null,
      orderIdList:[]   //选中项的订单id列表
    }
  },
  methods: {
    show(record) {
      this.visible = true
      // console.log('选中项', record)
      this.orderIdList = record.map((item)=>{ return item.orderId })
    },
    close() {
      this.visible = false
      this.num = 0
    },
    // 确认按钮
    confirmSubmit(){
      // 校验是否填写
      if(this.num!=0 && !this.num){
        this.$message.error("请输入正确的相似度值 (范围: 0 ~ 100 之间, 0为查询所有)")
        return
      }
      // 调取接口,获取数据
      this.axios.post('/emsOrder/recommendedProduction', {orderIdList:this.orderIdList, pro:this.num/100}).then((res)=>{
        if(res.success){ 
          this.$emit('getTableData',{data: res.data, beforeNum:this.num})
          this.visible = false
          this.num = 0
        }
      }).finally(()=>{
        this.num=0
        this.visible = false
      })
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
  },
}
</script>

<style lang="less">
.table-operator {
  margin-bottom: 18px;
}

button {
  margin-right: 8px;
}

.table-image {
  cursor: pointer;
  max-width: 100px;
  max-height: 50px;
  border: solid 1px #cccccc;
}
</style>
